package com.ficus.road.maintain.dao;

import com.ficus.road.maintain.core.dao.BaseMongoDao;
import com.ficus.road.maintain.core.dto.weather.WeatherDTO;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author nan.li
 * @date 2020.09.21
 */

@Component
public class WeatherMongoDao extends BaseMongoDao<WeatherDTO, String> {
    @Override
    protected String getCollectionName() {
        return "weather";
    }

    @Override
    protected void indexOperation() {
        super.getMongoTemplate().indexOps(getCollectionName())
                .ensureIndex(new Index().on("creation_time", Sort.Direction.DESC).expire(30, TimeUnit.DAYS).background());
    }
}